import axios from './config.js'

// 导出所有的 api 接口
export default {
    login(user) {
        console.log("即将登录，发出的内容是：", user)
        return axios.post('/api/token', user, { loading: true, permission: false });
    },

    getAccessToken(refreshToken) {
        // 刷新令牌，换取令牌
        return axios.post("/api/token/refresh", {refresh: refreshToken}, {permission: false});
    },

    register(user) {
        return axios.post('/user/user', user, { loading: true, permission: false });
    },

    // 获取班级列表
    clazz_list() {
        return axios.get('/user/user/find_clazz_list', { permission: false });
    },

    // 切换班级
    switch_clazz(clazz_id) {
        return axios.put('/user/user/switch_clazz', {clazz_id});
    },

    // 修改密码
    change_password(user) {
        console.log("修改密码，发出的内容是：", user);
        return axios.put('/user/user/change_password', user);
    },

    getTasks(params){
        return axios.get('/api/tasks', {params});
    },

    // 筛选接口
    check_task() {
        return axios.get("/task/condition", {})
    },

    // 查询任务接口
    select_task(params){
        return axios.get('/task/task', {params: params})
    },

    // 提交，修改，保存按钮代码接口
    submit_code(code) {
        return axios.post('/task/save_code', code)
    },

    // 开始，完成按钮接口
    start_end_task(data){
        return axios.post('/task/change_task',data)
    },

    // 获取当前班级下的学生信息
    current_stu_list(){
        return axios.get("task/task_cent/current_stu_list")
    },

    // 重置密码/禁用用户
    reset_password_active(id, sign){
        console.log("重置密码，发出的内容是：", id, sign);
        return axios.put("user/user/reset_password_active", {id, sign});
    },

    // 获取任务列表
    stucent_tasklist(params) {
        return axios.get("task/task_cent/stucent_tasklist", {params})
    },

    // 添加分配任务给学生的API
    assignTasksToStudent(data) {
        console.log("分配任务，发出的内容是：", data);
        return axios.post("task/task_cent/assign_tasks", data);
    },

    // 教师端任务中心，检查按钮
    teacher_check_button(task_id){
        return axios.get('task/teacher_check_button/teacher-task-answers',{params: {task_id}})
    },
    // 调用教师端查询任务接口
    teacher_select_tasklist(params){
        return axios.get('/task/teacher_select_task', {params: params})
    },


    groupAdd(data){
        return axios.post('/api/groups/create/', data);
    },

    getGroupList(params) {
        return axios.get('/api/groups/list/', { params });

    },

    getAllUsers(params) {
        return axios.get('/api/users/', { params });
  },

    getGroupUsers(groupId) {
        return axios.get(`/api/groups/${groupId}/users/`);
  },

    updateGroupUsers(groupId, userIds) {
        return axios.post(`/api/groups/${groupId}/users/`, { user_ids: userIds });
  },



    updateGroup(groupId, data) {
        return axios.put(`/api/groups/${groupId}/`,data);
    },


    deleteGroup(groupId) {
      return axios.delete(`/api/groups/${groupId}/`);
    },

    assignTasksToGroup(groupId, taskIds) {
        console.log(groupId, taskIds)
        return axios.post("task/task_cent/assign_tasks",{groupId, taskIds,});

},
    // 获取需要讲解的任务列表
    need_explain() {
        return axios.get("task/task_cent/need_explain");
    },

    // 重置任务
    reset_task(data) {
        console.log("重置任务，发出的内容是：", data);
        return axios.put("task/task_cent/reset_task", data);
    },

    assignTaskToUsers(data){
        return axios.post("task/assign_task", data);
    },

    getTaskAssignUsers(data){
        return axios.post('task/assign_task/get_assigned_users', data);
    }
}